package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximize-total-cost-of-alternating-subarrays/description/
 * @create 2025/9/5 15:59
 * @since JDK17
 */

public class Solution77 {
    public long maximumTotalCost(int[] nums) {
        int n = nums.length;
        long[] dp = new long[n + 1];
        dp[1] = nums[0];
        for (int i = 2; i <= n; i++) {
            dp[i] = Math.max(dp[i - 2] + nums[i - 2] + Math.abs(nums[i - 1]), dp[i - 1] + nums[i - 1]);
        }

        return dp[n];
    }
}
